package com.xci.platform.auth.core;

import com.xci.platform.auth.dao.DicDetailsDao;
import com.xci.platform.core.ITreeOperate;
import com.xci.platform.core.Tree;

import java.util.List;

public class DicDetailsTreeOperate implements ITreeOperate {

    /**
     * 字典明细数据访问对象
     */
    private final DicDetailsDao dicDetailsDao;
    private final String dicCode;

    public DicDetailsTreeOperate(String dicCode, DicDetailsDao dicDetailsDao) {
        this.dicDetailsDao = dicDetailsDao;
        this.dicCode = dicCode;
    }

    /**
     * 获取指定主键的排序路径
     *
     * @param id 主键
     */
    @Override
    public String queryPathById(String id) {
        return dicDetailsDao.queryPathById(id);
    }

    /**
     * 获取指定主键的子节点数
     *
     * @param id 主键
     */
    @Override
    public Integer queryChildCountById(String id) {
        return dicDetailsDao.queryChildCountById(id);
    }

    /**
     * 根据主键更新父节点以及排序路径
     *
     * @param id       主键
     * @param parentId 上级主键
     * @param path     排序路径
     */
    @Override
    public Integer updateParentAndPathById(String id, String parentId, String path) {
        return dicDetailsDao.updateParentAndPathById(id, parentId, path);
    }

    /**
     * 根据主键更新排序路径
     *
     * @param id   主键
     * @param path 排序路径
     */
    @Override
    public Integer updatePathById(String id, String path) {
        return dicDetailsDao.updatePathById(id, path);
    }

    /**
     * 根据主键更新叶子节点状态
     *
     * @param id   主键
     * @param leaf 叶子节点状态
     */
    @Override
    public Integer updateLeafById(String id, Integer leaf) {
        return dicDetailsDao.updateLeafById(id, leaf);
    }

    /**
     * 查询Tree模型列表
     */
    @Override
    public List<Tree> queryTreeModelList() {
        return dicDetailsDao.queryTreeModelList(dicCode,null);
    }
}
